// @ts-ignore
/* eslint-disable */
import request from '@/request'

/** 获取分享登录信息 POST /api/showShare/getShareLoginInfo/{shareId} */
export async function getShareLoginInfoUsingPost(
  shareId: string,
  options?: { [key: string]: any }
) {
  return request<API.Result>(`/api/showShare/getShareLoginInfo/${shareId}`, {
    method: 'POST',
    ...(options || {}),
  })
}

/** 获取分享信息 POST /api/showShare/getShareInfo */
export async function getShareInfoUsingPost(
  params: {
    /** 分享ID */
    shareId: string
  },
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/getShareInfo', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 验证分享码 POST /api/showShare/checkShareCode */
export async function checkShareCodeUsingPost(
  params: {
    /** 分享ID */
    shareId: string
    /** 分享码 */
    code: string
  },
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/checkShareCode', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 获取分享列表 POST /api/showShare/loadFileList */
export async function loadFileListUsingPost(
  body: API.ShowShareFileQueryDTO,
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/loadFileList', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  })
}

/** 获取文件夹目录信息 POST /api/showShare/getFolderInfo */
export async function getFolderInfoUsingPost(
  params: {
    /** 分享ID */
    shareId: string
    /** 路径 */
    path: string
  },
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/getFolderInfo', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 查看文件 GET /api/showShare/getFile/{shareId}/{fileId} */
export async function getFileUsingGet(
  shareId: string,
  fileId: string,
  options?: { [key: string]: any }
) {
  return request<any>(`/api/showShare/getFile/${shareId}/${fileId}`, {
    method: 'GET',
    ...(options || {}),
  })
}

/** 创建分享文件下载链接 POST /api/showShare/createDownloadUrl */
export async function createDownloadUrlUsingPost(
  params: {
    /** 分享ID */
    shareId: string
    /** 文件ID列表 */
    fileIds: string
  },
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/createDownloadUrl', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 加载文件夹 POST /api/showShare/loadMyFolder/{filePid} */
export async function loadMyFolderUsingPost(filePid: string, options?: { [key: string]: any }) {
  return request<API.Result>(`/api/showShare/loadMyFolder/${filePid}`, {
    method: 'POST',
    ...(options || {}),
  })
}

/** 下载文件 GET /api/showShare/download/{shareId}/{fileId} */
export async function downloadUsingGet(
  shareId: string,
  fileId: string,
  options?: { [key: string]: any }
) {
  return request<any>(`/api/showShare/download/${shareId}/${fileId}`, {
    method: 'GET',
    responseType: 'blob',
    ...(options || {}),
  })
}

/** 保存分享文件 POST /api/showShare/saveShare */
export async function saveShareUsingPost(
  params: {
    /** 分享ID */
    shareId: string
    /** 分享文件ID列表 */
    shareFileIds: string
    /** 目标文件夹ID */
    myFolderId: string
  },
  options?: { [key: string]: any }
) {
  return request<API.Result>('/api/showShare/saveShare', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

// 加载我的文件夹
const loadMyFolders = async () => {
  try {
    const res = await loadMyFolderUsingPost('0')
    if (res.data?.code === 200 && res.data.data) {
      folderTree.value = formatFolderTree(res.data.data)
    }
  } catch (error) {
    message.error('获取文件夹列表失败')
  }
}
